package net.bingosoft.common.security.tag.toolbar;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
 * 2007-9-24 上午10:57:36
 * Author:yangdongyu(yangdy@bingosoft.net)
 * ReadMe:按钮标签
 * ChangeLog:
 */
public class ToolTag extends BodyTagSupport implements Cloneable{
	
	private static final long serialVersionUID = 1L;
	protected static final Log log = LogFactory.getLog(ToolTag.class);
	private String id;
	private String title;
	private String style;
	private String styleClass;
	private String onclick;
	private String imageURL;
	private String imageStyle;
	private String imageStyleClass;
	private String expression;
	private int order;
	private boolean isSeparator;
	private boolean visible = true;
	private boolean disabled = true;
	private String template;
	private String type ;
	private String name;
	
	
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	/**
	 * get request
	 * @return
	 */
	public HttpServletRequest getRequest(){
		return (HttpServletRequest)pageContext.getRequest();
	}
	/**
	 * @return the expression
	 */
	public String getExpression() {
		return expression;
	}

	/**
	 * @param expression the expression to set
	 */
	public void setExpression(String expression) {
		this.expression = expression;
	}


	/**
	 * @return the imageURL
	 */
	public String getImageURL() {
		return imageURL;
	}

	/**
	 * @param imageURL the imageURL to set
	 */
	public void setImageURL(String imageURL) {
		this.imageURL = imageURL;
	}

	/**
	 * @return the isSeparator
	 */
	public boolean isSeparator() {
		return isSeparator;
	}

	/**
	 * @param isSeparator the isSeparator to set
	 */
	public void setIsSeparator(boolean isSeparator) {
		this.isSeparator = isSeparator;
	}

	/**
	 * @return the onclick
	 */
	public String getOnclick() {
		return onclick;
	}

	/**
	 * @param onclick the onclick to set
	 */
	public void setOnclick(String onclick) {
		this.onclick = onclick;
	}

	/**
	 * @return the order
	 */
	public int getOrder() {
		return order;
	}

	/**
	 * @param order the order to set
	 */
	public void setOrder(int order) {
		this.order = order;
	}

	/**
	 * @return the style
	 */
	public String getStyle() {
		return style;
	}

	/**
	 * @param style the style to set
	 */
	public void setStyle(String style) {
		this.style = style;
	}

	/**
	 * @return the styleClass
	 */
	public String getStyleClass() {
		return styleClass;
	}

	/**
	 * @param styleClass the styleClass to set
	 */
	public void setStyleClass(String styleClass) {
		this.styleClass = styleClass;
	}

	/**
	 * @return the template
	 */
	public String getTemplate() {
		return template;
	}

	/**
	 * @param template the template to set
	 */
	public void setTemplate(String template) {
		this.template = template;
	}

	/**
	 * @return the title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * @param title the title to set
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * @return the useable
	 */
	public boolean isDisabled() {
		return disabled;
	}

	/**
	 * @param useable the useable to set
	 */
	public void setDisabled(boolean useable) {
		this.disabled = useable;
	}

	/**
	 * @return the visible
	 */
	public boolean isVisible() {
		return visible;
	}

	/**
	 * @param visible the visible to set
	 */
	public void setVisible(boolean visible) {
		this.visible = visible;
	}

	/**
	 * @return the imageStyle
	 */
	public String getImageStyle() {
		return imageStyle;
	}

	/**
	 * @param imageStyle the imageStyle to set
	 */
	public void setImageStyle(String imageStyle) {
		this.imageStyle = imageStyle;
	}

	/**
	 * @return the imageStyleClass
	 */
	public String getImageStyleClass() {
		return imageStyleClass;
	}

	/**
	 * @param imageStyleClass the imageStyleClass to set
	 */
	public void setImageStyleClass(String imageStyleClass) {
		this.imageStyleClass = imageStyleClass;
	}
	
	/* (non-Javadoc)
	 * @see javax.servlet.jsp.tagext.TagSupport#doAfterBody()
	 */
	@Override
	public int doAfterBody() throws JspException {
		if(super.getBodyContent() != null){
			this.template = super.getBodyContent().getString();
		}
		return super.doAfterBody();
	}
	
	/* (non-Javadoc)
	 * @see javax.servlet.jsp.tagext.TagSupport#doEndTag()
	 */
	@Override
	public int doEndTag() throws JspException {
		if(this.isVisible()){//父标签的子标签列表中都是可见的子标签
			getParent().addChild(this);
		}
		return EVAL_PAGE;
	}
	
	/* (non-Javadoc)
	 * @see javax.servlet.jsp.tagext.TagSupport#getParent()
	 */
	@Override
	public ToolBarTag getParent() {
		return (ToolBarTag)super.getParent();
	}
	public ToolTag clone(){
		ToolTag self = null;
		try {
			self = (ToolTag)super.clone();
		} catch (CloneNotSupportedException e) {
			e.printStackTrace();
		}
		return self;
	}

	/**
	 * @return the id
	 */
	public String getId() {
		return id;
	}

	/**
	 * @param id the id to set
	 */
	public void setId(String id) {
		this.id = id;
	}

}
